<?php

namespace app\admin\controller;

use app\common\model\Express as press;

class Express extends Base
{
    public function __construct()
    {
        parent::__construct();
        $this->isLogin();
    }


    /**
     * @route('express/expresslist')
     * 快递列表
     */
    public function ExpressList()
    {
        $Model = new press();

        $get['express_name'] = input('get.express_name');
        $get['status'] = input('get.status');

        $rs_data = $Model->get_list_page($get,'express_id asc','*',$this->limit);

        $tvar = array(
            "title" => "快递列表",
            "time"  => time(),
            "data"  => $rs_data,
            "get"   => $get,
        );
        $page = $rs_data->render();
        $this->assign("data", $tvar);
        $this->assign('page', $page);
        return $this->fetch('express/expresslist');
    }


    /**
     * @route('express/boxexpress')
     * 编辑分类
     */
    public function BoxExpress()
    {
        $Model = new press();

        if(request()->isAjax()){
            $type_id = input('express_id','0');
            $params['express_name'] = input('express_name');
            $params['express_code'] = input('express_code');
            $params['status'] = input('status');

            $rs_data = $Model->where('express_name', $params['express_name'])->where('express_code', $params['express_code'])->find();
            if($rs_data){
                $this->error('此快递已存在');
            }

            $rs = $Model->edit($params, $type_id);
            if($rs === false){
                $this->error($Model->getError());
            }
            $this->success('操作成功','/express/expresslist');
        }

        $type_id = input('get.express_id',0);
        $data = null;
        if($type_id != 0){
            $data = $Model->getOne(['express_id' => $type_id],'*');
        }


        $tvar = [
            'time' => time(),
            'title' => '编辑快递'
        ];
        $this->assign("data", $tvar);
        $this->assign("type", $data);
        return $this->fetch('express/boxexpress');
    }

    /**
     * @route('service/delservicetype')
     * 删除分类
     */
    public function DelServiceType()
    {
        $type_id = input('get.type_id');
        if($type_id > 0){
            $rs = ServiceType::destroy($type_id);
            if($rs === false){
                $this->error('操作失败');
            }
            $this->success('操作成功');
        }
    }




}